<template>
  <div id="confirmOrder">
    <div class="confirmOrder-header">
      <div class="confirmOrder-title">
        <i class="el-icon-s-order" style="color: #ff6700;"></i>
        确认订单
      </div>
    </div>
    <div class="bottom">
      <el-card>
        <p id="addres">收货地址</p>
        <ul id="box">
          <li>
            <p>陈同学</p>
            <p>13580018623</p>
            <p>广东&emsp;广州市&emsp;白云区&emsp;江高镇</p>
            <p>广东白云学院</p>
          </li>
          <li>
            <p>陈同学</p>
            <p>13580018623</p>
            <p>广东&emsp;茂名市&emsp;化州市&emsp;杨梅镇</p>
            <p>***</p>
          </li>
          <li>
            <div>
              <i class="el-icon-circle-plus-outline" style="fontSize:30px"></i>
              <p style="color:#757575; fontSize:16px">添加新地址</p>
            </div>
          </li>
        </ul>
        <p id="shop">商品优惠券</p>
        <ul id="list">
          <li>
            <ul v-for="item in getCheckGoods" :key="item.id">
              <li>
                <img :src="'http://39.100.7.70:81/'+item.productImg" alt />
                <span>{{item.productName}}</span>
              </li>
              <li>{{item.price}}x{{item.num}}</li>
              <li>{{item.num*item.price}}</li>
            </ul>
          </li>
          <li>
            <p>配送方式</p>
            <p>包邮</p>
          </li>
          <li>
            <p>发票</p>
            <p>
              电子发票
              <span>个人</span>商品明细
            </p>
          </li>
        </ul>
        <div id="bottom">
          <ul id="bottom">
            <li>
              <p>商品件数:</p>
              <p>{{getCheckNum}}件</p>
            </li>
            <li>
              <p>商品总价:</p>
              <p>{{getTotalPrice}}元</p>
            </li>
            <li>
              <p>活动优惠:</p>
              <p>-0元</p>
            </li>
            <li>
              <p>优惠券抵扣:</p>
              <p>-0元</p>
            </li>
            <li>
              <p>运费:</p>
              <p>0元</p>
            </li>
            <li>
              <p>应付总额:</p>
              <p>{{getTotalPrice}}元</p>
            </li>
          </ul>
        </div>
        <div id="butt">
          <button @click="getAddOrder()">结算</button>
          <button @click="$router.push('/shoppingCart')">返回购物车</button>
        </div>
      </el-card>
    </div>
  </div>
</template>

<script>
import { mapGetters, mapActions } from "vuex";
import Api from "@/api/confirmOrder.js";
import { Notification } from "element-ui";
export default {
  //import引入的组件需要注入到对象中才能使用
  components: {},
  props: {},
  data() {
    //这里存放数据
    return {};
  },
  //监控data中的数据变化
  watch: {},
  //方法集合
  methods: {
    ...mapActions(["deleteShoppingCarts"]),
    getAddOrder() {
      Api.getAddOrder({
        products: this.getCheckGoods,
        user_id: this.$store.state.user_id
      }).then(res => {
        const newData = this.getCheckGoods;
        console.log(res);
        if (res.data.code == "001") {
          for (var i = 0; i < newData.length; i++) {
            console.log(newData[i].id);
            this.deleteShoppingCarts(newData[i].id);
          }
          Notification.success({ title: "成功", message: res.data.msg });
          this.$router.push("/order");
        } else {
          Notification.success({ title: "失败", message: res.data.msg });
        }
      });
    }
  },
  computed: {
    ...mapGetters(["getCheckGoods", "getCheckNum", "getTotalPrice"])
  },
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {
    console.log(this.getCheckGoods);
//   this.getCheckGoods.forEach(item=>{
//     this.$store.state.checkData.push(item)
//   })
//  console.log(this.$store.state.checkData);
 
    
  },
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {},
  beforeCreate() {}, //生命周期 - 创建之前
  beforeMount() {}, //生命周期 - 挂载之前
  beforeUpdate() {}, //生命周期 - 更新之前
  updated() {}, //生命周期 - 更新之后
  beforeDestroy() {}, //生命周期 - 销毁之前
  destroyed() {}, //生命周期 - 销毁完成
  activated() {} //如果页面有keep-alive缓存功能，这个函数会触发
};
</script>
<style lang='scss' scoped>
#confirmOrder {
  background-color: #f5f5f5;
  .confirmOrder-header {
    height: 64px;
    background-color: #fff;
    border-bottom: 2px solid #ff6700;
    .confirmOrder-title {
      width: 1225px;
      padding: 0 200px;
      height: 64px;
      line-height: 58px;
      font-size: 28px;
    }
  }
}
.bottom {
  width: 100%;
  padding: 0 200px;
  .el-card {
    margin-top: 20px;
    display: flex;
    flex-direction: column;
    #addres {
      font-size: 23px;
    }
    #box {
      margin-top: 26px;
      margin-bottom: 40px;
      width: 1054px;
      height: 242px;
      // border: 1px solid #000;
      display: flex;
      justify-content: space-between;
      li {
        width: 336px;
        height: 242px;
        border: 1px solid #000;
        padding: 26px 0px 82px 32px;
        p {
          &:nth-of-type(1) {
            font-size: 22px;
          }
          &:nth-of-type(2) {
            font-size: 16px;
            color: #757575;
            margin: 24px 0;
          }
          &:nth-of-type(3),
          &:nth-of-type(4) {
            color: #757575;
            font-size: 16px;
          }
        }
        &:nth-of-type(1) {
          border: 1px solid #ff6700;
        }
        &:nth-of-type(3) {
          padding: 80px 130px;

          div {
            width: 98px;
            height: 62px;
            // border: 1px solid #000;
            display: flex;
            flex-direction: column;
            justify-content: space-between;
            align-items: center;
          }
        }
      }
    }
    #shop {
      font-size: 22px;
    }
    #list {
      width: 100%;
      //   height: 300px;
      // border: 1px solid #000;
      margin-top: 10px;
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      li {
        width: 100%;
        display: flex;
        align-items: center;

        &:nth-of-type(1) {
          display: flex;
          flex-direction: column;
          align-content: space-between;
          padding: 10px 0;
          justify-content: space-between;

          ul {
            width: 100%;
            border-top: 1px solid #e0e0e0;
            border-bottom: 1px solid #e0e0e0;
            display: flex;
            justify-content: space-between;
            align-items: center;
            li {
              border: none;
              img {
                width: 26px;
                height: 30px;
              }
            }
          }
        }
        &:nth-of-type(2) {
          height: 105px;
          p {
            &:nth-of-type(1) {
              width: 100px;
              font-size: 20px;
            }
            &:nth-of-type(2) {
              font-size: 16px;
              color: red;
            }
          }
        }
        &:nth-of-type(3) {
          height: 105px;
          p {
            &:nth-of-type(1) {
              width: 100px;
              font-size: 20px;
            }
            &:nth-of-type(2) {
              font-size: 16px;
              color: red;
              span {
                margin: 0 20px;
              }
            }
          }
        }
      }
    }
    #bottom {
      width: 100%;
      height: 296px;
      padding: 32px 0;
      display: flex;

      flex-direction: row-reverse;
      #bottom {
        width: 250px;
        height: 226px;
        display: flex;
        flex-direction: column;
        li {
          display: flex;
          justify-content: space-between;
          align-items: center;
          &:nth-of-type(6) {
            margin-top: 20px;
            p {
              &:nth-of-type(2) {
                color: red;
                font-size: 26px;
              }
            }
          }
          p {
            &:nth-of-type(1) {
              width: 100px;
              display: flex;
              flex-direction: row-reverse;
              color: #757575;
              font-size: 18px;
            }
            &:nth-of-type(2) {
              color: red;
              font-size: 20px;
            }
          }
        }
      }
    }
    #butt {
      width: 100%;
      height: 96px;
      padding: 22px 0;
      display: flex;

      flex-direction: row-reverse;
      button {
        width: 200px;
        height: 48px;
        text-align: center;
        line-height: 48px;
        cursor: pointer;
        &:nth-of-type(2) {
          margin-right: 36px;
          border: 1px solid #bababa;
          color: #bababa;
          background: white;
        }
        &:nth-of-type(1) {
          border: none;
          background: red;
          color: white;
        }
      }
    }
  }
}
</style>